// components/nav/index.js
const app = getApp()

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    key: {
      type: String,
      value: 'nav'
    },
    top: {
      type: String,
      value: '10'
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    bannerSize: 0
  },
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      this.init();
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    init: function (options) {
      //首页幻灯片
      var params = {};
      params.model = this.properties.key;
      params.needLogin = false;
      var func = this.backAdList.bind(this);
      app.postRequest("/rest/ad/list.htm", params, func);
    },
    backAdList(res) {
      if (res.code == 0) {
        this.setData({
          icons: res.list,
          bannerSize: res.list.length
        });
      }
    },
    showNav(event) {
      var object = event.currentTarget.dataset.object;
      if ("商家中心" == object.title) {
        var path = "pages/bootstrap/index?tenant=" + app.tenant;
        path = path + "&userToken=" + app.userToken;
        path=path+"&openId="+app.openId;
        console.info(path);
        wx.navigateToMiniProgram({
          appId: 'wxe499fee213d68c41',
          path: path
        })
        return
      }
      if (object.url && object.url.length > 5) {
        wx.navigateTo({
          url: object.url
        })
      }
      console.log(object);

    }
  }
})